// 获取年月日
function getYMD(value) {
    var year = value.getFullYear();
    year = year < 10 ? '0' + year : year;
    var month = value.getMonth() + 1;
    month = month < 10 ? '0' + month : month;
    var day = value.getDate();
    day = day < 10 ? '0' + day : day;
    return year + '-' + month + '-' + day
}

function getDateSlot(dayLength) {
    //  开始时间 设置为今天  Thu Aug 01 2019 15:00:01 GMT+0800 (中国标准时间)
    var startDate = new Date();
    // 初始化结束时间
    var endDate = new Date();
    // getDate可以返回当前日期表示天的数字。数字值介于1-31之间
    var num = startDate.getDate();
    endDate.setDate(num + dayLength);
    console.log("endDate : %s", getYMD(endDate))
    return getYMD(endDate)

};

function getCalendarData(dayLength) {
    //  开始时间 设置为今天  Thu Aug 01 2019 15:00:01 GMT+0800 (中国标准时间)
    var startDate = new Date();
    // 初始化结束时间
    var endDate = new Date();
    // getDate可以返回当前日期表示天的数字。数字值介于1-31之间
    var num = startDate.getDate();
    //  结束时间  用setDate设置今天之后的第30天日期作
    // 创建日期数组
    var dataArr = [];
    // 创建周数据
    var weeks = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
    endDate.setDate(num + dayLength);
    // while循环  结束时间与开始时间毫秒数相减
    while ((endDate.getTime() - startDate.getTime()) >= 0) {
        // 判断月，天长度 是否是1，是一位数前面加0 ，否则直接使用
        var month = (startDate.getMonth() + 1).toString().length == 1 ? "0" + (startDate.getMonth() + 1).toString() : (startDate.getMonth() + 1);
        var day = startDate.getDate().toString().length == 1 ? "0" + (startDate.getDate()) : (startDate.getDate());
        var week = weeks[startDate.getDay()];
        let state = num % 2 == 0 ? 1 : 0
        let regiNum = 0
        dataArr.push({
            weekText: week,
            fullDayText: getYMD(startDate),
            dayText: day,
            checked: false,
            regiNum: regiNum
        })
        startDate.setDate(startDate.getDate() + 1);
    }
    return dataArr;
}

function gettimeslot(start, end) {
    let timeSlotArr = [];
    if (start > end) {
        let m = 0;
        m = start;
        start = end;
        end = m;
    }
    for (let i = start; i <= end; i++) {
        let item = '';
        if (i < 10) {
            item += "0" + i + ":00-"
        } else {
            item += i + ":00-"
        }
        if (i + 1 < 10) {
            item += "0" + (i + 1) + ":00"
        } else {
            item += (i + 1) + ":00"
        }
        let num = Math.floor(Math.random() * 25)
        let state = num % 2 == 0 ? 1 : 0
        let regiNum = num % 2 == 0 ? 10 : 0
        let obj = {
            text: item,
            state: state,
            check: false,
            regiNum: regiNum
        }
        timeSlotArr.push(obj)
    }
    console.log("Start : %s , End : %s , Slot: %o", start, end, timeSlotArr)
    return timeSlotArr
}

function getGX(type) {
    let text = ''
    switch (type) {
        case '00':
            text = "本人";
            break;
        case '01':
            text = "父母";
            break;
        case '02':
            text = "子女";
            break;
        case '03':
            text = "夫妻";
            break;
        case '04':
            text = "亲属";
            break;
        case '05':
            text = "朋友";
            break;
        case '06':
            text = "其他";
            break;
        case '07':
            text = "儿童";
            break;
        case '08':
            text = "儿童";
            break;
    }

    return text
}


export default {
    getCalendarData: getCalendarData,
    gettimeslot: gettimeslot,
    getGX: getGX,
    getDateSlot: getDateSlot
}
